// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import App from './App'
import router from './router'
import '@/rem.js'
Vue.config.productionTip = false
import axios from 'axios'
var instance = axios.create({
    baseURL: 'http://api.6x9hkan.cn/',
    timeout: 5000 // 请求超时时间
})
import Crypt from '@/aes.js';
instance.interceptors.request.use(config => {
    config.data = Crypt.enc(JSON.stringify(config.data));
    return config;
}, error => {
    Promise.reject(error)
})
instance.interceptors.response.use(response => {
    if (Crypt.dec(response.data)) {
        var data = JSON.parse(Crypt.dec(response.data))
        return data;
    } else {
        return {};
    }
}, error => {
    Promise.reject(error)
})
Vue.prototype.$axios = instance;
Vue.prototype.$get_time = () => {
    return (new Date()).getTime() / 1000;
}
router.beforeEach((to, from, next) => {
    if (to.meta.title) {
        document.title = to.meta.title
    }
    const type = to.path;
    // 判断该路由是否需要登录权限
    if (type != '/user/login' && type != '/') {
        if (localStorage.getItem('userId')) {
            next()
        } else {
            next('/user/login')
        }
    } else {
        next() // 确保一定要有next()被调用
    }
})
/* eslint-disable no-new */
new Vue({
    el: '#app',
    router,
    components: {
        App
    },
    template: '<App/>'
})